import {
  Body,
  Controller,
  Get,
  Post,
  Query,
  UseGuards,
  ValidationPipe,
} from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from 'src/common/jwt/JwtAuthGuard';
import { HttpReslut } from 'src/common/result/http-reslut';
import { FriendApplication } from 'src/entities/friendApplication.entity';
import { AddFriendDto } from './dto/add-friend.dto';
import { AgreeFriendDto } from './dto/agree_friend.dto';
import { FriendApplicationService } from './friend-application.service';

@ApiBearerAuth()
@UseGuards(new JwtAuthGuard())
@ApiTags('/添加好友模块')
@Controller('friendApplication')
export class FriendApplicationController {
  constructor(
    private readonly friendApplicationService: FriendApplicationService,
  ) {}

  @ApiOperation({
    summary: '添加好友',
  })
  @ApiBody({
    type: AddFriendDto,
  })
  @Post('/addFriend')
  async addFriend(@Body(new ValidationPipe()) addFriendDto: AddFriendDto) {
    await this.friendApplicationService.addFriend(addFriendDto);
    return new HttpReslut<boolean>(true);
  }

  @ApiOperation({
    summary: '同意好友添加',
  })
  @ApiBody({
    type: AgreeFriendDto,
  })
  @Post('/agreeFriend')
  agreeFriend(@Body(new ValidationPipe()) agreeFriend: AgreeFriendDto) {
    this.friendApplicationService.agreeFriend(agreeFriend);
    return new HttpReslut<boolean>(true);
  }

  @ApiOperation({
    summary: '获取添加好友列表',
  })
  @Get('/findList')
  async findAll(@Query('userId') userId: string) {
    let friendApplicationList = await this.friendApplicationService.findAll(
      userId,
    );
    return new HttpReslut<FriendApplication[]>(friendApplicationList);
  }
}
